package b3.widget.basic
{
	import b3.net.*;
	import b3.util.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;

	public class DebugPane extends Sprite
	{
		private var contentContainer:Sprite;
		private static var instance:DebugPane;
		private var count:int;
		private var currentPosY:Number;

		public function DebugPane()
		{
			super();
			contentContainer = new Sprite();
			currentPosY = 0;
			count = 0;
			this.addEventListener(MouseEvent.CLICK, onMouseClick);
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);
		}
		
		private function onAddedToStage(event:Event):void
		{
			while (this.numChildren > 0)
				this.removeChildAt(0);
			var content:Sprite = new Sprite();
			contentContainer.y = contentContainer.height + 30;
			content.addChild(contentContainer);
			addChild(content);
			var gfx:Graphics = content.graphics;
			gfx.beginFill(0xFFFFFF);
			gfx.drawRect(0, 0, BFont.stageWidth, BFont.stageHeight);
			gfx.endFill();
			var messageText:TextField = new TextField();
        	messageText.autoSize = TextFieldAutoSize.CENTER;
        	messageText.background = true;
        	messageText.backgroundColor = 0xFFFFFF;
			messageText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);;
			messageText.x = BFont.stageHeight / 2;
			messageText.text = "~~ 客户端版本" + Profile.VERSION + "：调试信息显示，请点击鼠标继续游戏！~~";
			addChild(messageText);
		    var scrollBar:FullScreenScrollBar = new FullScreenScrollBar(content, 0xAAAAAA, 0x555555, 0x666666, 0xffffff, 15, 15, 4, true);
		    addChild(scrollBar);
		}
		
		public static function getInstance():DebugPane
		{
			if (!instance)
				instance = new DebugPane();
			return instance;
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			close();
		}	
		
		public function close():void
		{
			if (this.parent != null)
				this.parent.removeChild(this);
		}
		
		public function addInfo(text:String):void
		{
			var messageText:TextField = new TextField();
        	messageText.autoSize = TextFieldAutoSize.LEFT;
        	messageText.width = BFont.stageWidth;
        	messageText.wordWrap = true;
			messageText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);;
			if (text != null)
				messageText.text = text;
			currentPosY -= messageText.height;
			messageText.x = 10;
			messageText.y = currentPosY;
			contentContainer.addChild(messageText);
			var gfx:Graphics = contentContainer.graphics;
			gfx.beginFill(count % 2 == 0 ? 0xAAAAAA : 0xFFFFFF);
			gfx.drawRect(0, currentPosY, BFont.stageWidth, messageText.height);
			gfx.endFill();
			count++;
		}
		
	}
}